package com.edu.koTA07.xmlHandler;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.edu.koTA07.XmlDataSet.SalesXmlDataSet;

public class SalesXMLHandler extends DefaultHandler {

	Boolean currentElement = false;
	String currentValue = null;
	public static SalesXmlDataSet sales = null;

	public static SalesXmlDataSet getSalesList() {
		return sales;
	}

	public static void setSalesList(SalesXmlDataSet salesList) {
		SalesXMLHandler.sales = salesList;
	}

	/** Called when tag starts ( ex:- <name>AndroidPeople</name> 
	 * -- <name> )*/
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {

		currentElement = true;

		if (localName.equals("ListSales"))
		{
			/** Start */ 
			sales = new SalesXmlDataSet();
		} 

	}

	/** Called when tag closing ( ex:- <name>AndroidPeople</name> 
	 * -- </name> )*/
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {

		currentElement = false;

		/** set value */ 
		if (localName.equalsIgnoreCase("id_sales"))
			sales.setIDSales(currentValue);
		else if (localName.equalsIgnoreCase("id_perusahaan"))
			sales.setIDPerusahaan(currentValue);
		else if (localName.equalsIgnoreCase("nama_sales"))
			sales.setNamaSales(currentValue);
		else if (localName.equalsIgnoreCase("username"))
			sales.setUsername(currentValue);
		else if (localName.equalsIgnoreCase("password"))
			sales.setPassword(currentValue);


	}

	/** Called to get tag characters ( ex:- <name>AndroidPeople</name> 
	 * -- to get AndroidPeople Character ) */
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {

		if (currentElement) {
			currentValue = new String(ch, start, length);
			currentElement = false;
		}

	}

}
